//
//  SQLiteHelper.h
//  Etion
//
//  Created by  user on 11-3-21.
//  Copyright 2011 GuangZhouXuanWu. All rights reserved.
//

#import <Foundation/Foundation.h>

#import <sqlite3.h>

#import "XMSGUID.h"

#import "XMSQueueDictionary.h"

typedef NSInteger(^ExecCallBack)(XMSQueueDictionary *qd);

@interface XMSSQLiteHelper : NSObject
{
    sqlite3 *m_sqlhandle;
    sqlite3_stmt *m_statement;
    BOOL m_bHandler;

    ExecCallBack m_execcallback;
}

@property(nonatomic, readonly) sqlite3 *m_sqlhandle;

//废弃
- (id)initWithSQLHandler:(sqlite3 *)sqlhandle;

- (id)initWithSQLiteHelper:(XMSSQLiteHelper *)sqlitehelper;

- (NSInteger)createTable:(const char *)szSQL path:(NSString *)szPath;

- (NSInteger)createTable:(const char *)szSQL psw:(const char *)szPsw path:(NSString *)szPath;

- (NSInteger)openTable:(NSString *)szPath flags:(NSInteger)flags;

- (NSInteger)openTable:(NSString *)szPath psw:(const char *)szPsw flags:(NSInteger)flags;

- (NSInteger)openTable:(sqlite3 *)sqlhandle;

- (void)closeTable;

- (NSInteger)modifyDBPassword:(NSString *)szPath oldPsw:(const char *)szOldpsw newPsw:(const char *)szNewpsw;

- (NSInteger)prepareExecSQL:(const char *)szSQL;

//废弃
//返回101正常
- (NSInteger)execSQL;

//废弃
- (NSInteger)runSQL;

//废弃
//返回101正常
- (NSInteger)immediateExecSQL:(const char *)szSQL;

//返回1正常
- (NSInteger)immediateRunSQL:(const char *)szSQL;

//废弃
//返回101正常
- (NSInteger)immediateExecSQL:(const char *)szSQL changerows:(NSUInteger *)nRow;

//返回1正常
- (NSInteger)immediateRunSQL:(const char *)szSQL changerows:(NSUInteger *)nRow;

- (NSInteger)execStatement;

- (void)finalizeStatement;

- (BOOL)selectRowContinue;

- (BOOL)selectRowContinue:(NSInteger *)nResult;

- (NSInteger)changeRows;

- (NSInteger)getColumnCount;

- (NSInteger)getColumnType:(NSUInteger)nIndex;

- (NSString *)getColumnName:(NSUInteger)nIndex;

//废弃
- (NSInteger)exec:(void (^)())function;

//废弃
//返回101正常
- (NSInteger)exec2:(NSInteger (^)())function;

//废弃
//返回0正常
- (NSInteger)exec:(const char *)szSQL callBack:(ExecCallBack)callback;

//返回1正常
//block中返回1正常
- (NSInteger)transExce:(NSInteger (^)())function;

- (NSInteger)getTable:(const char *)szSQL gettingTable:(void (^)(NSUInteger nRow, NSUInteger nCol, NSString *szColname, NSString *szColvalue))gettable;

- (NSInteger)selectTable:(const char *)szSQL gettingTable:(void (^)(BOOL *bStop))gettable;

- (void)putFieldNull:(NSUInteger)nIndex;

- (void)putFieldInt:(NSUInteger)nIndex param:(NSInteger)param;

- (NSInteger)getFieldInt:(NSUInteger)nIndex;

- (NSNumber*)getFieldNSNumberInt:(NSUInteger)nIndex;

- (void)putFieldLongLong:(NSUInteger)nIndex param:(long long)param;

- (long long)getFieldLongLong:(NSUInteger)nIndex;

- (NSNumber*)getFieldNSNumberLongLong:(NSUInteger)nIndex;

- (void)putFieldDouble:(NSUInteger)nIndex param:(double)param;

- (double)getFieldDouble:(NSUInteger)nIndex;

- (void)putFieldNSString:(NSUInteger)nIndex param:(NSString *)param;

- (NSString *)getFieldNSString:(NSUInteger)nIndex;

- (void)putFieldGUID:(NSUInteger)nIndex param:(GUID)param;

- (GUID)getFieldGUID:(NSUInteger)nIndex;

- (void)putFieldByte:(NSUInteger)nIndex param:(Byte *)param length:(NSUInteger)nLength;

- (Byte *)getFieldByte:(NSUInteger)nIndex length:(NSUInteger *)nLength;

- (void)putFieldNSDate:(NSUInteger)nIndex param:(NSDate *)datetime;

- (NSDate *)getFieldNSDate:(NSUInteger)nIndex;

- (void)putFieldNSData:(NSUInteger)nIndex param:(NSData *)param;

- (NSData*)getFieldNSData:(NSUInteger)nIndex;

- (XMSQueueDictionary *)getTableHeads:(NSString *)szTable;

+ (NSString *)replaceSpecialString:(NSString *)szStr;

@end
